home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-15 | 3.8 KB | 151 lines | [TEXT/PJMM] |
- program MungeInstaller;
-
- uses
- EPPC, AppleEvents, RequiredEventSupport, MyDriver, MungeLibs, MungeCommon;
-
- const
- Driver_Name = '.MungeImage';
-
- var
- drvr_ref: integer;
- quitNow: boolean;
- have_opened: boolean;
-
- function MyProgress (pb: mungeParamBlockPtr): OSErr;
- begin
- pb^.refcon := band(pb^.refcon + 1, $03);
- SetCursor(GetCursor(128 + pb^.refcon)^^);
- MyProgress := noErr;
- end; (* MyProgress *)
-
- function DoODoc (fss: FSSpec; option: boolean): OSErr;
- var
- err: OSErr;
- pb: mungeParamBlockRec;
- begin
- have_opened := true;
- with pb do begin
- ioCRefNum := drvr_ref;
- csCode := csMountImageWithProgress;
- file_to_mount := @fss;
- mount_flags := 0;
- if option then begin
- bset(mount_flags, mf_read_write);
- end; (* if *)
- progress := @MyProgress;
- refcon := 0;
- end; (* with *)
- err := PBControlSync(@pb);
- if err = controlErr then begin
- pb.csCode := csMountImage;
- err := PBControlSync(@pb);
- end; (* if *)
- if err <> noErr then begin
- SysBeep(10);
- end; (* if *)
- quitNow := true;
- DoODoc := err;
- end; (* DoODoc *)
-
- function HandleDocs (event, reply: AppleEvent; dodocp: ptr): OSErr;
- var
- myFSS: FSSpec;
- docList: AEDescList;
- index, itemsInList: LONGINT;
- actualSize: Size;
- keywd: AEKeyword;
- typeCode: descType;
- oe, ooe, err: OSErr;
- er: EventRecord;
- realType: DescType;
- realSize: longInt;
- psn: ProcessSerialNumber;
- pi: ProcessInfoRec;
- odoc_with_option: boolean;
- begin
- err := AEGetParamBoolean(event, 'auto', odoc_with_option);
- if err <> noErr then begin
- odoc_with_option := false;
- err := AEGetAttributePtr(event, keyAddressAttr, keyProcessSerialNumber, realType, @psn, SizeOf(psn), realSize);
- if err = noErr then begin
- pi.processInfoLength := sizeof(ProcessInfoRec);
- pi.processName := nil;
- pi.processAppSpec := nil;
- err := GetProcessInformation(psn, pi);
- end;
- if (err = noErr) & (pi.processSignature = 'MACS') then begin
- odoc_with_option := OSEventAvail(everyEvent, er);
- odoc_with_option := BAND(er.modifiers, optionKey) <> 0;
- end;
- end;
- oe := AEGetParamDesc(event, keyDirectObject, typeAEList, docList);
- if oe = noErr then begin
- ooe := GotRequiredParams(event);
- { now get each alias from the list (as an FSSSpec) and open the associated file. }
- oe := AECountItems(docList, itemsInList);
- for index := 1 to itemsInList do begin
- ooe := AEGetNthPtr(docList, index, typeFSS, keywd, typeCode, @myFSS, sizeof(myFSS), actualSize);
- { coercion does alias->fsspec }
- if ooe = noErr then begin
- ooe := DoODoc(myFSS, odoc_with_option);
- end; (* if *)
- end;
- ooe := AEDisposeDesc(docList);
- end;
- HandleDocs := oe;
- end; { HandleDocs }
-
- function DoOApp: OSErr;
- begin
- quitNow := true;
- DoOApp := noErr;
- end;
-
- function DoQuit: OSErr;
- begin
- quitNow := true;
- DoQuit := noErr;
- end; (* DoQuit *)
-
- var
- junkbool: boolean;
- event: EventRecord;
- err: OSErr;
- junk: OSErr;
- junk_vref: integer;
- response: longint;
- begin
- if (Gestalt(gestaltSystemVersion, response) <> noErr) | (response < $700) then begin
- ExitToShell;
- end; (* if *)
- err := InitAppleEvents(@DoOApp, nil, nil, @DoQuit);
- if err = noErr then begin
- err := AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, @HandleDocs, 0, false);
- end; (* if *)
- if err = noErr then begin
- drvr_ref := GetDriverRefNum(Driver_Name);
- if drvr_ref <> 0 then begin
- err := noErr;
- end
- else begin
- err := InstallRAMDriver(Driver_Name, drvr_ref, true);
- end;
- if err = noErr then begin
- quitNow := false;
- while not quitNow do begin
- junkbool := WaitNextEvent(everyEvent, event, maxlongint, nil);
- case event.what of
- keyDown:
- quitNow := true;
- kHighLevelEvent:
- junk := AEProcessAppleEvent(event);
- otherwise
- ;
- end; (* case *)
- end; (* while *)
- end; (* if *)
- end; (* if *)
- if err <> noErr then begin
- SysBeep(10);
- end;
- end. (* MungeInstaller *)